package com.example.winner.weight;

import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    public static String sex="M";
    private EditText et;
    private String str_height;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button b=(Button)findViewById(R.id.calculate);
        et=(EditText)findViewById(R.id.et_height);
        RadioGroup rg=(RadioGroup)findViewById(R.id.rg_sex);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                if(checkedId==R.id.male)
                {
                    sex="M";
                }
                else
                {
                    sex="F";
                }
            }
        });
        b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(MainActivity.this,Result.class);
                str_height=et.getText().toString();
                if(str_height.equals(""))
                {
                    Toast.makeText(MainActivity.this,"身高不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }
                double height=Double.parseDouble(str_height);
                Bundle bundle=new Bundle();
                bundle.putDouble("height",height);
                bundle.putString("sex",sex);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }
}
